<html>
<head>
  <title>SwAddin中的对象</title>
  <basefont face="微软雅黑" size="2" />
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <meta name="exporter-version" content="Evernote Windows/307027 (zh-CN, DDL); Windows/6.1.0 (Win32);"/>
  <style>
    body, td {
      font-family: 微软雅黑;
      font-size: 10pt;
    }
  </style>
</head>
<body>
<a name="697"/>
<h1>SwAddin中的对象</h1>

<div>
<span><div><div><span><font style="font-size: 14pt; color: rgb(28, 51, 135);"><b>SolidWorks API Object Model</b></font></span></div><div><span><br/></span></div><div><ul><li><span><span style="line-height: 1.45;"><font style="font-size: 12pt;"><b>ISldWorks object</b></font></span><br/></span></li></ul><div><span>    <span>    <span>    is the application object; it is the top-level object in the SolidWorks API object hierarchy. All of the other SolidWorks objects are located below the ISldWorks object in the object hierarchy and can be accessed directly or indirectly.</span></span></span><br/></div></div><div><span>    <span>    <span>    indirectly: you must reference that object from another object higher in the object hierarchy.For example, the <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.ISketchSpline.html">ISketchSpline</a> object can only be accessed indirectly; it cannot exist on its own. You must reference the ISketchSpline object from the <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.ISketchSegment.html">ISketchSegment</a> object because it exists only within the context of the ISketchSegment object.</span></span></span></div><div><span style="line-height: 1.45;"><span>    <span>    <span>    user-interface: Most of the SolidWorks API object correspond to user-interface functionality; however, several SolidWorks API objects provide functionality only accessible through the SolidWorks API. For example, the <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IFeature.html">IFeature</a> object lets you access features in the FeatureManager design tree, but the <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IAttribute.html">IAttribute</a> object is a SolidWorks API-only object because there is no corresponding user-interface functionality.</span></span></span></span></div><div><span style="line-height: 1.45;"><br/></span></div><div><span style="line-height: 1.45;"><font style="color: rgb(28, 51, 135); font-size: 14pt;"><b>SolidWorks API Class Hierachy</b></font></span></div><div><span style="line-height: 1.45;"><br/></span></div><div><span style="line-height: 1.45;">SolidWorks does not document its APIs with a complete a class hierarchy diagram, much like the famous MFC and .NET/WinFX class hierarchy diagrams. The reason for this is that MFC and .NET rely heavily on:</span></div><div><span style="line-height: 1.45;"><span>    </span> </span><span style="line-height: 1.45;">          </span><span style="line-height: 1.45;">    </span><span style="line-height: 1.45;">        </span></div><ul style="list-style: disc;"><li><span style="-en-paragraph: true;">Classes</span></li><li><span style="-en-paragraph: true;">Implementation inheritance</span></li><li><span style="-en-paragraph: true;">Casting between classes using static casts (C++)</span></li></ul><div><br/></div><div><span style="-en-paragraph: true;">These types of class libraries and APIs can often benefit from a hierarchy diagram.</span></div><div style="-en-paragraph: true; margin-top: 1em; margin-bottom: 1em;"><span style="-en-paragraph: true;"> However, SolidWorks is a COM-based API that uses:</span></div><ul style="list-style: disc;"><li><span style="-en-paragraph: true;">Interfaces</span></li><li><span style="-en-paragraph: true;">Interface inheritance</span></li><li><span style="-en-paragraph: true;">Factory methods to return interfaces on existing and new objects</span></li><li><span style="-en-paragraph: true;">Casting between interfaces through:</span></li><ul style="list-style: disc;" type="disc"><li>QueryInterface (C++), which <span style="color: rgb(0, 0, 0);">returns a pointer to a specified interface on an object to which a client currently holds an interface pointer.</span></li><li>direct assignment (VB/<a href="http://vb.net/">VB.NET</a>).</li><li>the <span style="font-weight: bold;">is/as</span> reserved words (C#).</li></ul></ul><div><span style="-en-paragraph: true;">While a graphical hierarchy diagram often does not convey as much information in this style of API, there are a few places where it can be useful.</span></div><div><br/></div><div><h2><font color="#1C3387">Interface Inheritance in the SolidWorks API</font></h2></div><div><span style="-en-paragraph: true;">Objects that implement:</span></div><ul style="list-style: disc;"><li><a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IAssemblyDoc.html" style="-en-paragraph: true;">IAssemblyDoc</a><span style="-en-paragraph: true;">,</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IDrawingDoc.html" style="-en-paragraph: true;">IDrawingDoc</a><span style="-en-paragraph: true;">, or</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IPartDoc.html" style="-en-paragraph: true;">IPartDoc</a> <span style="-en-paragraph: true;">can QueryInterface to</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IModelDoc2.html" style="-en-paragraph: true;">IModelDoc2</a><span style="-en-paragraph: true;">.  </span></li><li><a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IEdge.html" style="-en-paragraph: true;">IEdge</a><span style="-en-paragraph: true;">,</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IFace2.html" style="-en-paragraph: true;">IFace2</a><span style="-en-paragraph: true;">,</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IFeature.html" style="-en-paragraph: true;">IFeature</a><span style="-en-paragraph: true;">,</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.ILoop2.html" style="-en-paragraph: true;">ILoop2</a><span style="-en-paragraph: true;">, or</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IVertex.html" style="-en-paragraph: true;">IVertex</a> <span style="-en-paragraph: true;">can QueryInterface to</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IEntity.html" style="-en-paragraph: true;">IEntity</a><span style="-en-paragraph: true;">.</span></li><li><a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IBomTableAnnotation.html" style="-en-paragraph: true;">IBomTableAnnotation</a><span style="-en-paragraph: true;">,</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IHoleTableAnnotation.html" style="-en-paragraph: true;">IHoleTableAnnotation</a><span style="-en-paragraph: true;">,</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IRevisionTableAnnotation.html" style="-en-paragraph: true;">IRevisionTableAnnotation</a><span style="-en-paragraph: true;">, or</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IWeldmentCutListAnnotation.html" style="-en-paragraph: true;">IWeldmentCutListAnnotation</a> <span style="-en-paragraph: true;">can QueryInterface to</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.ITableAnnotation.html" style="-en-paragraph: true;">ITableAnnotation</a><span style="-en-paragraph: true;">.</span></li><li><a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IAttribute.html" style="-en-paragraph: true;">IAttribute</a> <span style="-en-paragraph: true;">also can QueryInterface to</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IFeature.html" style="-en-paragraph: true;">IFeature</a><span style="-en-paragraph: true;">.</span></li><li><a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.ISketchArc.html" style="-en-paragraph: true;">ISketchArc</a><span style="-en-paragraph: true;">,</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.ISketchEllipse.html" style="-en-paragraph: true;">ISketchEllipse</a><span style="-en-paragraph: true;">,</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.ISketchLine.html" style="-en-paragraph: true;">ISketchLine</a><span style="-en-paragraph: true;">,</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.ISketchParabola.html" style="-en-paragraph: true;">ISketchParabola</a><span style="-en-paragraph: true;">,</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.ISketchPoint.html" style="-en-paragraph: true;">ISketchPoint</a><span style="-en-paragraph: true;">,</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.ISketchSpline.html" style="-en-paragraph: true;">ISketchSpline</a><span style="-en-paragraph: true;">, or</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.ISketchText.html" style="-en-paragraph: true;">ISketchText</a> <span style="-en-paragraph: true;">can QueryInterface to</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.ISketchSegment.html" style="-en-paragraph: true;">ISketchSegment</a><span style="-en-paragraph: true;">.</span></li><li><span style="-en-paragraph: true;">PropertyManager page controls, such as</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IPropertyManagerPageActiveX.html" style="-en-paragraph: true;">IPropertyManagerPageActiveX</a><span style="-en-paragraph: true;">,</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IPropertyManagerPageBitmap.html" style="-en-paragraph: true;">IPropertyManagerPageBitmap</a><span style="-en-paragraph: true;">,</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IPropertyManagerPageBitmapButton.html" style="-en-paragraph: true;">IPropertyManagerPageBitmapButton</a><span style="-en-paragraph: true;">,</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IPropertyManagerPageButton.html" style="-en-paragraph: true;">IPropertyManagerPageButton</a><span style="-en-paragraph: true;">, etc., can QueryInterface to</span> <a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IPropertyManagerPageControl.html" style="-en-paragraph: true;">IPropertyManagerPageControl</a><span style="-en-paragraph: true;">.</span></li></ul><h3 style="margin: 0cm; margin-bottom: .0001pt;"><span style="font-size: 12.0pt; font-family: 宋体; color: blue;"><br/></span></h3><h3 style="margin: 0cm; margin-bottom: .0001pt;"><span style="font-size: 12.0pt; font-family: 宋体; color: blue;"><br/></span></h3><h3 style="margin: 0cm; margin-bottom: .0001pt;"><span style="font-size: 12.0pt; font-family: 宋体; color: blue;">QueryInterface</span></h3><div style="text-indent: 21pt; -en-paragraph: true; margin-top: 1em; margin-bottom: 1em;"><span style="text-indent: 21pt; -en-paragraph: true; font-family: 宋体;">IUnknown</span><span style="text-indent: 21pt; -en-paragraph: true; font-family: 宋体;">的一个成员函数</span><span style="text-indent: 21pt; -en-paragraph: true; color: #010001;">QueryInterface</span><span style="text-indent: 21pt; -en-paragraph: true; font-family: 宋体; color: #010001;">，客户可以通过此函数来查询某个组件是否支持某个特定的接口。若支持</span><span style="text-indent: 21pt; -en-paragraph: true; color: #010001;">QueryInterface</span><span style="text-indent: 21pt; -en-paragraph: true; font-family: 宋体; color: #010001;">将返回一个</span><span style="text-indent: 21pt; -en-paragraph: true; font-family: 宋体; color: #010001;">指向些</span><span style="text-indent: 21pt; -en-paragraph: true; font-family: 宋体; color: #010001;">接口的指针，不支持返回值将是一个错误代码。</span><span style="color: rgb(1, 0, 1); font-family: 宋体; text-indent: 21pt; line-height: 1.45;"> </span></div><div style="-en-paragraph: true; margin-top: 1em; margin-bottom: 1em;"><span style="-en-paragraph: true; color: #010001;">QueryInterface</span> <span style="-en-paragraph: true; font-family: 宋体; color: #010001;">有两个参数，和一个</span><span style="-en-paragraph: true; color: #010001;">HRESULT</span><span style="-en-paragraph: true; font-family: 宋体; color: #010001;">返回值</span></div><div style="-en-paragraph: true; margin-top: 1em; margin-bottom: 1em;"><span style="-en-paragraph: true; color: #010001;">HRESULT</span> <span style="-en-paragraph: true; font-family: 宋体; color: #010001;">__stdcall</span> <span style="-en-paragraph: true; color: red;">QueryInterface</span><span style="-en-paragraph: true;">(</span> <span style="-en-paragraph: true; color: #010001;">REFIID</span> <span style="-en-paragraph: true; color: #010001;">riid</span><span style="-en-paragraph: true;">,</span> <span style="-en-paragraph: true; color: blue;">void</span> <span style="-en-paragraph: true;">**</span> <span style="-en-paragraph: true; color: #010001;">ppvObject</span><span style="-en-paragraph: true;">)</span><span style="-en-paragraph: true; font-family: 宋体;">;</span></div><div style="-en-paragraph: true; margin-top: 1em; margin-bottom: 1em;"><span style="line-height: 1.45; font-family: 宋体;">第一个参数：接口标识符（</span><span style="line-height: 1.45;">IID</span><span style="line-height: 1.45; font-family: 宋体;">）</span></div><div style="-en-paragraph: true; margin-top: 1em; margin-bottom: 1em;"><span style="-en-paragraph: true; font-family: 宋体;">第二个参数：存放所请求接口指针的地址。</span></div><div><span style="-en-paragraph: true; font-family: 宋体;">返回值：查询成功返回</span><span style="-en-paragraph: true;">S_OK</span><span style="-en-paragraph: true; font-family: 宋体;">，如果不成功则返回相应错误码。</span></div><div><br/></div><div><br/></div><h2><font color="#1C3387" style="font-size: 14pt;">Using methods as an alternative to QueryInterface/Interface inheritance</font></h2><div style="-en-paragraph: true; margin-top: 1em; margin-bottom: 1em;"><span style="-en-paragraph: true;">There are several other areas of the API that use other methods to perform operations similar to a QueryInterface().</span></div><ul style="list-style: disc;"><li><a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IAnnotation%7EGetSpecificAnnotation.html" style="-en-paragraph: true;">IAnnotation::GetSpecificAnnotation</a> <span style="-en-paragraph: true;">can return:</span></li><ul style="list-style: disc;" type="disc"><li><a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.ICThread.html" style="-en-paragraph: true;">ICThread*</a></li><li><a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IGtol.html" style="-en-paragraph: true;">IGtol*</a></li><li><a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.INote.html" style="-en-paragraph: true;">INote*</a></li><li>others. See <a href="http://help.solidworks.com/2013/English/api/swconst/SolidWorks.interop.swconst%7ESolidWorks.interop.swconst.swAnnotationType_e.html">swAnnotationType_e</a> for a list of the types that can be returned<br/><span style="-en-paragraph: true;"> </span></li></ul><li><span style="-en-paragraph: true;"> </span><a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IFeature%7EGetSpecificFeature2.html" style="-en-paragraph: true;">IFeature::GetSpecificFeature2</a> <span style="-en-paragraph: true;">can return:</span></li><ul style="list-style: disc;" type="disc"><li><a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IAttribute.html" style="-en-paragraph: true;">IAttribute*</a></li><li><a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.IMate2.html" style="-en-paragraph: true;">IMate2*</a></li><li><a href="http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.interop.sldworks%7ESolidWorks.interop.sldworks.ISketch.html" style="-en-paragraph: true;">ISketch*</a></li><li><span style="-en-paragraph: true;">others.</span></li></ul></ul><div><br/></div></div></span>
</div></body></html> 